/**
 * 
 */
package leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhong
 *
 */
public class GroupsofSpecialEquivalentStrings {
	class CharAndCnt {
		int[][] chCnt = new int[2][26];

		public CharAndCnt(String string) {
			for (int i = 0; i < string.length(); i++) {
				chCnt[i % 2][string.charAt(i) - 'a']++;
			}
		}

		@Override
		public boolean equals(Object obj) {
			CharAndCnt other = (CharAndCnt) obj;
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 26; j++) {
					if (other.chCnt[i][j] != chCnt[i][j]) {
						return false;
					}
				}

			}
			return true;
		}
	}

	public int numSpecialEquivGroups(String[] A) {
		List<CharAndCnt> groups = new ArrayList<>();
		for (String string : A) {
			CharAndCnt charAndCnt = new CharAndCnt(string);
			boolean ex = false;
			for (CharAndCnt exCharAndCnt : groups) {
				if (charAndCnt.equals(exCharAndCnt)) {
					ex = true;
					break;
				}
			}
			if (!ex) {
				groups.add(charAndCnt);
			}
		}
		return groups.size();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String[] A = { "a", "v", "h", "v", "a" };
		System.out.println(new GroupsofSpecialEquivalentStrings().numSpecialEquivGroups(A));
	}

}
